//
//  QZHongBaoXianjinDetailsVC.m
//  shortvideoplay
//
//  Created by tikeios_002 on 2024/7/29.
//

#import "QZHongBaoXianjinDetailsVC.h"
#import "QZHongBaoXianjinDetailsCell.h"
#import "PublicView.h"
#import "CSJADLoading.h"

@interface QZHongBaoXianjinDetailsVC ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (strong, nonatomic) UICollectionView *xianjinCollection;
@property (nonatomic, strong) NSMutableArray * listArr;
@property (nonatomic, assign) NSInteger requestPage;
@property (nonatomic, strong) PublicView * nullView;
@property (nonatomic, strong) UIView * adView;
@end

@implementation QZHongBaoXianjinDetailsVC

-(void)showTextViewNavViewTo1{
    NSMutableArray * showTextViewNavViewNameArrTo1 = [NSMutableArray new];
    UIView * showTextViewNavViewViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    showTextViewNavViewViewTo1.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:showTextViewNavViewViewTo1];
    UILabel * showTextViewNavViewLabelTo1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    NSInteger showTextViewNavViewNumberTo1 = arc4random_uniform(20);
    NSLog(@"：%ld", (long)showTextViewNavViewNumberTo1);
    showTextViewNavViewLabelTo1.text = [NSString stringWithFormat:@"%ld",(long)showTextViewNavViewNumberTo1];
    [showTextViewNavViewLabelTo1 addSubview:showTextViewNavViewLabelTo1];
    
    UIImageView * showTextViewNavViewLabelTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [showTextViewNavViewViewTo1 addSubview:showTextViewNavViewLabelTo2];
}
- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"现金明细";
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.minimumLineSpacing = 0.0;
    flowLayout.minimumInteritemSpacing = 0.0;
    flowLayout.footerReferenceSize = CGSizeZero;
    flowLayout.headerReferenceSize = CGSizeZero;
    flowLayout.sectionInset = UIEdgeInsetsZero;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    flowLayout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
    //创建collectionView 通过一个布局策略layout来创建
    self.xianjinCollection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, KScreen_W, KScreen_H-KNav_H-48) collectionViewLayout:flowLayout];
    self.xianjinCollection.backgroundColor = viewback_black;
    if (@available(iOS 11.0, *)) {
        self.xianjinCollection.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    //代理设置
    self.xianjinCollection.scrollsToTop = NO;
    self.xianjinCollection.delegate=self;
    self.xianjinCollection.dataSource=self;
    self.xianjinCollection.pagingEnabled = YES;
    self.xianjinCollection.showsVerticalScrollIndicator = NO;
    self.xianjinCollection.showsHorizontalScrollIndicator = NO;
    //注册item类型 这里使用系统的类型
    [self.xianjinCollection registerNib:[UINib nibWithNibName:@"QZHongBaoXianjinDetailsCell" bundle:nil] forCellWithReuseIdentifier:@"QZHongBaoXianjinDetailsCell"];
    
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:self.xianjinCollection];
    
    KWeakSelf
    self.xianjinCollection.mj_header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
        [weakSelf.xianjinCollection.mj_footer resetNoMoreData];
        weakSelf.requestPage = 0;
        [weakSelf activityTaskListRequest];
    }];
    self.xianjinCollection.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        weakSelf.requestPage = weakSelf.requestPage+1;
        [weakSelf activityTaskListRequest];
    }];
    [SVProgressHUDTool showWithStatus:nil];
    [self activityTaskListRequest];
    
    _adView = [[UIView alloc]init];
    _adView.layer.cornerRadius = 6;
    _adView.clipsToBounds = YES;
    _adView.backgroundColor = [UIColor clearColor];
    _adView.frame = CGRectMake(0, KScreen_H-45, KScreen_W, 0);
       UILabel * oldshowSSSSTip3 = [[UILabel alloc]init];
    oldshowSSSSTip3.clipsToBounds = YES;
    oldshowSSSSTip3.text = @"kass显示区";
    oldshowSSSSTip3.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip3.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip3.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip3.hidden = YES;
    [self.view addSubview:oldshowSSSSTip3];
    [self.view addSubview:_adView];
    
    [CSJADLoading share].BannerAdsLoadFish = ^(id  _Nullable bannerView) {
        if(bannerView != nil && weakSelf.xianjinCollection){
            weakSelf.xianjinCollection.frame = CGRectMake(0, 0, KScreen_W, KScreen_H-KNav_H-KSafeAreaBottomHeight-45);
            weakSelf.adView.frame = CGRectMake(0, KScreen_H-45-KNav_H-KSafeAreaBottomHeight, KScreen_W, 45);
            [weakSelf.adView addSubview:bannerView];
            [bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(weakSelf.adView);
            }];
            [UIView animateWithDuration:0.3 animations:^{
                [weakSelf.view layoutIfNeeded];
            }];
        }
    };
    [CSJADLoading ADBannerAdRequest:self];
}
- (NSMutableArray *)listArr{
    if(_listArr == nil){
        _listArr = [NSMutableArray new];
    }
    return _listArr;
}
- (PublicView *)nullView{
    if(_nullView == nil){
        _nullView = [[PublicView alloc]initWithFrame:CGRectMake(0, (KScreen_H-KNav_H)/2-100, KScreen_W, 200)];
        _nullView.publicLabel.text = @"还没有现金到账明细哦~";
        _nullView.hidden = YES;
        _nullView.userInteractionEnabled = NO;
           UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:_nullView];
    }
    return _nullView;
}
- (void)activityTaskListRequest{
    KMutableDic(sendDic)
    KWeakSelf
    sendDic[@"page"] = @(self.requestPage);
    [YBNetBase integrationWalletListNumberRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        [SVProgressHUDTool dismiss];
        if(code == 200){
            if(weakSelf.requestPage == 0){
                [weakSelf.listArr removeAllObjects];
            }
            [weakSelf.listArr addObjectsFromArray:data[@"list"]];
            [weakSelf.xianjinCollection reloadData];
            if(weakSelf.xianjinCollection.mj_header.isRefreshing){
                [weakSelf.xianjinCollection.mj_header endRefreshing];
            }else if (weakSelf.xianjinCollection.mj_footer.isRefreshing){
                if([data[@"list"] count] == 0){
                    [weakSelf.xianjinCollection.mj_footer endRefreshingWithNoMoreData];
                }else{
                    [weakSelf.xianjinCollection.mj_footer endRefreshing];
                }
            }else{
                if(weakSelf.listArr.count == 0){
                    weakSelf.nullView.hidden = NO;
                    weakSelf.xianjinCollection.mj_header.hidden = YES;
                    weakSelf.xianjinCollection.mj_footer.hidden = YES;
                }else{
                    weakSelf.nullView.hidden = YES;
                    weakSelf.xianjinCollection.mj_header.hidden = NO;
                    weakSelf.xianjinCollection.mj_footer.hidden = NO;
                }
            }
        }else{
            [YBMsgPop showPop:msg];
        }
    }];
}
#pragma mark uitableview delege
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.listArr.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    QZHongBaoXianjinDetailsCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QZHongBaoXianjinDetailsCell" forIndexPath:indexPath];
    cell.detailsName.text = self.listArr[indexPath.row][@"description"];
    cell.detailsTip.text = self.listArr[indexPath.row][@"createtime"];
    if([self.listArr[indexPath.row][@"method"] intValue] == 1){
        cell.detailsNumber.text = [NSString stringWithFormat:@"+%@",self.listArr[indexPath.row][@"amount"]];
        cell.detailsNumber.textColor = MainColor;
    }else{
        cell.detailsNumber.text = [NSString stringWithFormat:@"-%@",self.listArr[indexPath.row][@"amount"]];
        cell.detailsNumber.textColor = UIColor.whiteColor;
    }
    return cell;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView
 layout:(UICollectionViewLayout *)collectionViewLayout
insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
    
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(KScreen_W, 70);
}
- (void)showTextViewSubViewToViewTo1:(UIView * )subView{

    UIView * showTextViewSubViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    showTextViewSubViewTo1.clipsToBounds = YES;
    [subView addSubview:showTextViewSubViewTo1];
    UILabel * showTextViewSubViewLabelTo2 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    showTextViewSubViewLabelTo2.text = @"56464645";
    [showTextViewSubViewTo1 addSubview:showTextViewSubViewLabelTo2];
    
    UIImageView * showTextViewSubViewTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [subView addSubview:showTextViewSubViewTo2];

}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
}


@end
